package com.ruoyi.zsyh.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.ZtreeString;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zsyh.mapper.ZsyhPlatformPartstypeMapper;
import com.ruoyi.zsyh.domain.ZsyhPlatformPartstype;
import com.ruoyi.zsyh.service.IZsyhPlatformPartstypeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 产品分类Service业务层处理
 * 
 * @author yuexl
 * @date 2021-12-08
 */
@Service
public class ZsyhPlatformPartstypeServiceImpl implements IZsyhPlatformPartstypeService 
{
    @Autowired
    private ZsyhPlatformPartstypeMapper zsyhPlatformPartstypeMapper;

    /**
     * 查询产品分类
     * 
     * @param id 产品分类ID
     * @return 产品分类
     */
    @Override
    public ZsyhPlatformPartstype selectZsyhPlatformPartstypeById(String id)
    {
        return zsyhPlatformPartstypeMapper.selectZsyhPlatformPartstypeById(id);
    }

    /**
     * 查询产品分类列表
     * 
     * @param zsyhPlatformPartstype 产品分类
     * @return 产品分类
     */
    @Override
    public List<ZsyhPlatformPartstype> selectZsyhPlatformPartstypeList(ZsyhPlatformPartstype zsyhPlatformPartstype)
    {
        return zsyhPlatformPartstypeMapper.selectZsyhPlatformPartstypeList(zsyhPlatformPartstype);
    }

    /**
     * 新增产品分类
     * 
     * @param zsyhPlatformPartstype 产品分类
     * @return 结果
     */
    @Override
    public int insertZsyhPlatformPartstype(ZsyhPlatformPartstype zsyhPlatformPartstype)
    {
        zsyhPlatformPartstype.setId(IdWorker.getId());
        zsyhPlatformPartstype.setCreateTime(DateUtils.getNowDate());
        return zsyhPlatformPartstypeMapper.insertZsyhPlatformPartstype(zsyhPlatformPartstype);
    }

    /**
     * 修改产品分类
     * 
     * @param zsyhPlatformPartstype 产品分类
     * @return 结果
     */
    @Override
    public int updateZsyhPlatformPartstype(ZsyhPlatformPartstype zsyhPlatformPartstype)
    {
        zsyhPlatformPartstype.setUpdateTime(DateUtils.getNowDate());
        return zsyhPlatformPartstypeMapper.updateZsyhPlatformPartstype(zsyhPlatformPartstype);
    }

    /**
     * 删除产品分类对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteZsyhPlatformPartstypeByIds(String ids)
    {
        return zsyhPlatformPartstypeMapper.deleteZsyhPlatformPartstypeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除产品分类信息
     * 
     * @param id 产品分类ID
     * @return 结果
     */
    @Override
    public int deleteZsyhPlatformPartstypeById(String id)
    {
        return zsyhPlatformPartstypeMapper.deleteZsyhPlatformPartstypeById(id);
    }

    /**
     * 查询产品分类树列表
     * 
     * @return 所有产品分类信息
     */
    @Override
    public List<ZtreeString> selectZsyhPlatformPartstypeTree()
    {
        List<ZsyhPlatformPartstype> zsyhPlatformPartstypeList = zsyhPlatformPartstypeMapper.selectZsyhPlatformPartstypeList(new ZsyhPlatformPartstype());
        List<ZtreeString> ztrees = new ArrayList<ZtreeString>();
        for (ZsyhPlatformPartstype zsyhPlatformPartstype : zsyhPlatformPartstypeList)
        {
            ZtreeString ztree = new ZtreeString();
            ztree.setId(zsyhPlatformPartstype.getId());
            ztree.setpId(zsyhPlatformPartstype.getpId());
            ztree.setName(zsyhPlatformPartstype.getTypeName());
            ztree.setTitle(zsyhPlatformPartstype.getTypeName());
            ztrees.add(ztree);
        }
        return ztrees;
    }

    /**
     * 查询产品分类树列表
     *
     * @return 所有产品分类信息
     */
    @Override
    public List<ZtreeString> selectZsyhPlatformPartstypeTreeFirst()
    {
        ZsyhPlatformPartstype zsyhPlatformPartstype = new ZsyhPlatformPartstype();
        zsyhPlatformPartstype.setpId("0");
        List<ZsyhPlatformPartstype> zsyhPlatformPartstypeList = zsyhPlatformPartstypeMapper.selectZsyhPlatformPartstypeList(zsyhPlatformPartstype);
        List<ZtreeString> ztrees = new ArrayList<ZtreeString>();
        for (ZsyhPlatformPartstype temp : zsyhPlatformPartstypeList)
        {
            ZtreeString ztree = new ZtreeString();
            ztree.setId(temp.getId());
            ztree.setpId(temp.getpId());
            ztree.setName(temp.getTypeName());
            ztree.setTitle(temp.getTypeName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
